# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/5/9'
# __name__ = 'renderer.py'
from rest_framework.renderers import BaseRenderer
# import json
from rest_framework.settings import api_settings
from rest_framework.utils import encoders, json
# Create your code here.

class ElementUIRenderer(BaseRenderer):
    media_type = 'application/json'
    format = 'json'
    encoder_class = encoders.JSONEncoder
    ensure_ascii = not api_settings.UNICODE_JSON
    compact = api_settings.COMPACT_JSON
    strict = api_settings.STRICT_JSON
    def render(self, data, accepted_media_type=None, renderer_context=None):
        # return data
        # return json.dumps({'code': 20000, 'data': data})

        ret = json.dumps(
            {'code': 20000, 'data': data}, cls=self.encoder_class,
            indent=4, ensure_ascii=self.ensure_ascii,
            allow_nan=not self.strict
        )

        # We always fully escape \u2028 and \u2029 to ensure we output JSON
        # that is a strict javascript subset.
        # See: http://timelessrepo.com/json-isnt-a-javascript-subset
        ret = ret.replace('\u2028', '\\u2028').replace('\u2029', '\\u2029')
        return ret.encode()